package com.snopy.jarfile;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

/**
 * @author snopy
 * @version 1.0.0
 * @classname DemoReadJar
 * @description
 * @email 77912204@qq.com
 * @date 2022/12/06 17:47
 */
@Slf4j
public class DemoReadJar {
    public static void main(String[] args) {
        JarFile jarFile = null;
        try {
            jarFile = new JarFile("F:\\opt\\dataease\\plugins\\上海智迩智能科技有限公司\\view-3dpie-backend-1.0-SNAPSHOT.jar");

            log.info("version:{},Manifest:{},name:{}"
                    ,jarFile.getVersion()
                    ,jarFile.getManifest()
                    ,jarFile.getName());
            Enumeration<JarEntry> entries = jarFile.entries();
            List<String> list = new ArrayList<>();
            while (entries.hasMoreElements()){
                JarEntry entry = entries.nextElement();
                if (entry.getRealName().endsWith(".class")){
                    list.add(entry.getRealName());
                }
            }
            if (list.size() > 0){
                list.forEach(c ->{
                    try {
                        Class<?> obj = Class.forName(c);

                    } catch (ClassNotFoundException e) {
                        throw new RuntimeException(e);
                    }
                });
            }


        } catch (IOException e) {
            throw new RuntimeException(e);
        }finally {
            if (jarFile!=null){
                try {
                    jarFile.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}
